package basics.day17.ArraysDemo;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        // sort_toString();
        // binarySearch();
        // 是个学生成绩
        int[] arr = {99, 100, 50, 60, 30, 70, 88, 67, 4, 56};
        int[] newArr = returnNewArr(arr);
        System.out.println(Arrays.toString(newArr));
    }

    /*
     * 定义方法，接收输入，存储的是10个人考试成绩
     * 将最后三个人的成绩存储到新数组中并返回出来
     * */
    public static int[] returnNewArr(int[] arr) {
        int[] newArr = new int[3];
        Arrays.sort(arr);
        System.arraycopy(arr, arr.length - 3, newArr, 0, 3);
        return newArr;
    }

    public static void binarySearch() {
        int[] ints = {1, 2, 3, 4, 5, 6, 7, 8, 90, 0};
        int index = Arrays.binarySearch(ints, 3);
        int index1 = Arrays.binarySearch(ints, 10);
        System.out.println(index); // 2
        System.out.println(index1); // -9
    }

    public static void sort_toString() {
        int[] ints = {2, 4, 5, 2, 5, 6, 8, 45, 7, 6, 3, 5, 6, 5, 3, 5, 45, 4, 43, 4};
        Arrays.sort(ints);
        // [2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 7, 8, 43, 45, 45]
        System.out.println(Arrays.toString(ints));
    }
}
